*Set the path of the "stata program and data" folder
clear
cd "E:\文稿\论文写作\肺炎\疫情信息公开\数据与代码"
***************
* Figure A.1  *
***************
use data_totalnumber.dta,clear
tsset date1,daily
twoway (tsline all_disclose ,msymbol(S) yaxis(1)) (tsline eastern_disclose ,msymbol(o) lpattern(dash_dot) yaxis(2)) (tsline central_disclose ,msymbol(o) lpattern(dash_dot) yaxis(2)) ///
       (tsline western_disclose ,msymbol(o) lpattern(dash_dot) yaxis(2)),ttext(15 20jan2020 "Xi's instructions", size(small) orientation(vertical) lpattern(dash) lcolor(red)) ttext(20 23jan2020 "Wuhan's lockdown", size(small) orientation(vertical)) ///
	   tlabel(20jan2020 25jan2020 30jan2020 4feb2020 9feb2020 14feb2020 19feb2020 24feb2020 29feb2020, labsize(small)) tline(20jan2020 23jan2020, lpattern(dot) lcolor(Cranberry)) xtitle(" ") ///
       ytitle("The total number of prefectures starting to disclose the information", size(small) axis(1)) ytitle("The regional number of prefectures starting to disclose the informatione", size(small) axis(2)) ///
       legend(order(1 "All" 2 "Eastern" 3 "Central" 4 "Western")) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "GIGURE A.1.tif", as(tif) replace

***************
* Figure A.2  *
***************
use data_newlyconfirmedcases.dta,clear
tsset date1,daily
twoway (tsline dtotalconfirmed_nh ,msymbol(S) yaxis(1)) (tsline dtotalconfirmed_h ,msymbol(o) lpattern(dash_dot) yaxis(2)) ,ttext(500 01mar2020 "The end of our sample period",orientation(vertical)) tlabel(20jan2020 3feb2020 13feb2020 23feb2020 04mar2020 14mar2020) tline(3feb2020 12feb2020 29feb2020,lpattern(dash) lcolor(black)) ///
       xtitle("Day of Year") ytitle("Newly confirmed cases in other provinces excepet Hubei", axis(1)) ytitle("Newly confirmed cases in Hubei province", axis(2)) ///
       legend(order(1 "Other provinces excepet Hubei" 2 "Hubei province")) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "GIGURE A.2.tif", as(tif) replace

***************
* Figure A.3  *
***************
use "data_map.dta",clear
spmap number using "data_mapall.dta", id(id) clnumber(11) fcolor(Reds2) ocolor(none ..) legstyle(2) legend(ring(0) position(7))  
graph export "GIGURE A.3.tif", as(tif) replace

***************
* Figure A.4  *
***************
use data.dta,clear
xtset citycode time
keep if time<open_time
bysort citycode: egen index_mean = mean(index)
keep citycode citys E_citys index_mean open_time 
duplicates drop
regress open_time index_mean, robust
twoway (scatter open_time index_mean, msymbol(circle_hollow) mcolor(navy) mlabel(E_citys) mlabcolor(navy)), subtitle(" ", size(small)) ///
       ytitle("Accumulated days before information disclosure since 19 January 2020") ytitle(, size(small)) ylabel(, labsize(small) angle(horizontal) nogrid) ///
       xtitle("Average daily Baidu index of COVID-19 before information disclosure") xtitle(, size(small) margin(medsmall)) xlabel(, labsize(small)) ///
       legend(off) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "GIGURE A.4.tif", as(tif) replace


***************
*   Table 1   *
***************
use data.dta,clear
xtset citycode time
xi: nbreg index c.L.county ,r nolog
est store m1
xi: nbreg index c.L.county i.citycode ,r nolog
est store m2
xi: nbreg index c.L.county i.citycode i.time ,r nolog
est store m3
outreg2 [m1 m2 m3] using Table1.doc,replace bdec(4) sdec(4)

***************
*  Figure 1   *
***************
use data.dta,clear
xtset citycode time
gen order=time-open_time
drop if open_time==0
replace order=-20 if order <= -20
replace order=30 if order >= 30
forvalues i = 20(-1)1{
gen pre_`i' = (order==-`i')
}
gen current = (order==0)
forvalues j = 1(1)30{
gen post_`j'=(order == `j')
}
nbreg index pre_* post_* i.citycode i.time,r nolog
est store nbreg
coefplot nbreg,keep(pre_* current post_*) coeflabels(pre_20="-20" pre_19="-19" pre_18="-18" pre_17="-17" pre_16="-16" pre_15="-15" pre_14="-14" pre_13="-13" pre_12="-12" pre_11="-11" pre_10="-10" pre_9="-9" pre_8="-8" pre_7="-7" pre_6="-6" pre_5="-5" pre_4="-4" pre_3="-3" pre_2="-2" pre_1="-1" ///
         current= "0" post_30="30" post_29="29" post_28="28" post_27="27" post_26="26" post_25="25" post_24="24"  post_23="23" post_22="22" post_21="21" post_20="20" post_19="19" post_18="18" post_17="17" post_16="16" post_15="15" post_14="14" post_13="13" post_12="12" post_11="11" post_10="10" post_9="9" post_8="8" post_7="7" post_6="6" post_5="5" post_4="4" post_3="3" post_2="2" post_1="1") vertical recast(connect)  ///
         yline(0, lwidth(vthin) lpattern(dash) lcolor(teal)) xline(20.5,lwidth(vthin) lpattern(dash) lcolor(teal)) ytitle("Search Query" , size(small)) xtitle("Days" , size(small))  ///
         ylabel(, labsize(small) angle(horizontal) nogrid) addplot(line @b @at ,lcolor(gs0) lwidth(thin)) xlabel(, labsize(small)) ciopts(lpattern(dash) recast(rcap) msize(medium))  ///
         msymbol(circle_hollow) scheme(s1momo) legend(off) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph export "GIGURE 1.tif", as(tif) replace

***************
*   Table 2   *
***************
use data.dta,clear
drop if county==1
xtset citycode time
xi: nbreg index c.L.s_county i.citycode i.time ,r nolog
est store m1
xi: nbreg index c.L.m_county i.citycode i.time ,r nolog
est store m2
outreg2 [m1 m2] using Table2.doc,replace bdec(4) sdec(4)

***************
*   Table 3   *
***************
use data.dta,clear
xtset citycode time
xi:nbreg index c.L.county c.L.county#c.Enforcementdays i.citycode i.time,r nolog
est store m1
xi:nbreg index c.L.county c.L.county#c.Discredit i.citycode i.time,r nolog
est store m2
xi:nbreg index c.L.county c.L.county#c.Fiscaltransparence i.citycode i.time,r nolog
est store m3
outreg2 [m1 m2 m3] using Table3.doc,replace bdec(4) sdec(4)

***************
*  Figure 2   *
***************
use data.dta,clear
xtset citycode time
qui nbreg index c.L.county c.L.county#c.Enforcementdays i.citycode i.time,r nolog
margins, dydx(L.county) at(Enforcementdays==(1.12(0.4)5.12))
marginsplot, yline(0, lwidth(vthin) lpattern(dash) lcolor(red)) title(" " , size(small)) ytitle("Marginal Effects" , size(small))  ///
xtitle("Enforcement days" , size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph save Graph "Figure2.1.gph",replace

qui:nbreg index c.L.county c.L.county#c.Discredit i.citycode i.time,r nolog
margins, dydx(L.county) at(Discredit==(0(1)10))
marginsplot, yline(0, lwidth(vthin) lpattern(dash) lcolor(red)) title(" " , size(small)) ytitle("Marginal Effects" , size(small))  ///
xtitle("Discredit" , size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph save Graph "Figure2.2.gph",replace

qui:nbreg index c.L.county c.L.county#c.Fiscaltransparence i.citycode i.time,r nolog
margins, dydx(L.county) at(Fiscaltransparence==(25.5(4)69.5))
marginsplot, yline(0, lwidth(vthin) lpattern(dash) lcolor(red)) title(" " , size(small)) ytitle("Marginal Effects" , size(small))  ///
xtitle("Fiscal transparence" , size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph save Graph "Figure2.3.gph",replace

graph combine Figure2.1.gph Figure2.2.gph Figure2.3.gph ,row(3)
graph export "GIGURE 2.tif", as(tif) replace

***************
*   Table 4   *
***************
use data.dta,clear
xtset citycode time
xi: nbreg index c.L.county c.L.county#c.Governmenttrust1 i.citycode i.time ,r nolog
est store m1
xi: nbreg index c.L.county c.L.county#c.Governmenttrust2 i.citycode i.time ,r nolog
est store m2
xi:nbreg index c.L.county c.L.county#c.Trustinthelegalsystem i.citycode i.time,r nolog
est store m3
outreg2 [m1 m2 m3] using Table4.doc,replace bdec(4) sdec(4)

***************
*  Figure 3   *
***************
use data.dta,clear
xtset citycode time
qui: nbreg index c.L.county c.L.county#c.Governmenttrust1 i.citycode i.time ,r nolog
margins, dydx(L.county) at(Governmenttrust1==(3.33(0.2)5.33))
marginsplot, yline(0, lwidth(vthin) lpattern(dash) lcolor(red)) title(" " , size(small)) ytitle("Marginal Effects" , size(small))  ///
xtitle("Government trust 1" , size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph save Graph "Figure3.1.gph",replace

qui: nbreg index c.L.county c.L.county#c.Governmenttrust2 i.citycode i.time ,r nolog
margins, dydx(L.county) at(Governmenttrust2==(0.1(2)22.1))
marginsplot, yline(0, lwidth(vthin) lpattern(dash) lcolor(red)) title(" " , size(small)) ytitle("Marginal Effects" , size(small))  ///
xtitle("Government trust 2" , size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph save Graph "Figure3.2.gph",replace

qui:nbreg index c.L.county c.L.county#c.Trustinthelegalsystem i.citycode i.time,r nolog
margins, dydx(L.county) at(Trustinthelegalsystem==(53.2(2.5)78.2))
marginsplot, yline(0, lwidth(vthin) lpattern(dash) lcolor(red)) title(" " , size(small)) ytitle("Marginal Effects" , size(small))  ///
xtitle("Trust in legal system" , size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph save Graph "Figure3.3.gph",replace

graph combine Figure3.1.gph Figure3.2.gph Figure3.3.gph ,row(3)
graph export "GIGURE 3.tif", as(tif) replace

***************
*   Table 5   *
***************
use data.dta,clear
sort citycode time
gen dcase=case-case[_n-1]
replace dcase=0 if lcase==0
xtset citycode time
gen Confirmed=ln(dcase+1)
xi: xtreg Confirmed c.L.county i.citycode i.time,fe
est store m1
xi: xtreg F.Confirmed c.L.county i.citycode i.time,fe
est store m2
xi: xtreg F2.Confirmed c.L.county i.citycode i.time,fe
est store m3
xi: xtreg F3.Confirmed c.L.county i.citycode i.time,fe
est store m4
xi: xtreg F4.Confirmed c.L.county i.citycode i.time,fe
est store m5
xi: xtreg F5.Confirmed c.L.county i.citycode i.time,fe
est store m6
xi: xtreg F6.Confirmed c.L.county i.citycode i.time,fe
est store m7
xi: xtreg F7.Confirmed c.L.county i.citycode i.time,fe
est store m8
xi: xtreg F8.Confirmed c.L.county i.citycode i.time,fe
est store m9
xi: xtreg F9.Confirmed c.L.county i.citycode i.time,fe
est store m10
xi: xtreg F10.Confirmed c.L.county i.citycode i.time,fe
est store m11
xi: xtreg F11.Confirmed c.L.county i.citycode i.time,fe
est store m12
xi: xtreg F12.Confirmed c.L.county i.citycode i.time,fe
est store m13
xi: xtreg F13.Confirmed c.L.county i.citycode i.time,fe
est store m14
xi: xtreg F14.Confirmed c.L.county i.citycode i.time,fe
est store m15
xi: xtreg F15.Confirmed c.L.county i.citycode i.time,fe
est store m16
xi: xtreg F16.Confirmed c.L.county i.citycode i.time,fe
est store m17
xi: xtreg F17.Confirmed c.L.county i.citycode i.time,fe
est store m18
xi: xtreg F18.Confirmed c.L.county i.citycode i.time,fe
est store m19
xi: xtreg F19.Confirmed c.L.county i.citycode i.time,fe
est store m20
xi: xtreg F20.Confirmed c.L.county i.citycode i.time,fe
est store m21
outreg2 [m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19 m20 m21] using Table5.doc,replace bdec(4) sdec(4) keep(L.county) addtext(Prefecture,Yes,Day,Yes)

***************
*   Table 6   *
***************
use data.dta,clear
xtset citycode time
gen Confirmed=ln(case+1)
gen Fatality=ln(dead+1)
xi: xtreg Fatality c.L.county L.Confirmed,r
est store m1
xi: xtreg Fatality c.L.county L.Confirmed i.citycode ,fe
est store m2
xi: xtreg Fatality c.L.county L.Confirmed i.citycode i.time ,fe
est store m3
outreg2 [m1 m2 m3] using Table6.doc,replace bdec(4) sdec(4) 

